package com.health.viewscontrols;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.health.R;

public class MoreSearch extends NovaActivity {

    private EditText etSearch;
    private ImageView iv_search;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresearch);

        findViews();
        setListeners();
    }

    @Override
    public void findViews() {
        iv_search = (ImageView)findViewById(R.id.iv_search);
        etSearch = (EditText)findViewById(R.id.et_search);
    }

    @Override
    public void setListeners() {
        iv_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null == etSearch.getText().toString() || etSearch.getText().toString().equals("")){
                    Toast.makeText(MoreSearch.this, "请完善搜索信息", Toast.LENGTH_SHORT).show();
                }else{
                    Intent inte = new Intent();
                    inte.putExtra("data",etSearch.getText().toString().trim());//这里是键值对，“data”是键
                    setResult(200,inte);//返回值，2 是改返回的标志，也会返回
                    finish();//销毁当前页面
                }
            }
        });
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                    if(null == etSearch.getText().toString() || etSearch.getText().toString().equals("")){
                        Toast.makeText(MoreSearch.this, "请完善搜索信息", Toast.LENGTH_SHORT).show();
                    }else{
                        Intent inte = new Intent();
                        inte.putExtra("data",etSearch.getText().toString().trim());//这里是键值对，“data”是键
                        setResult(200,inte);//返回值，2 是改返回的标志，也会返回
                        finish();//销毁当前页面
                    }
                return false;
            }
        });
    }
}
